package lacus.wd_cinema.controller.api;

import jakarta.servlet.http.HttpServletRequest;
import lacus.wd_cinema.dto.auth.LoginRequest;
import lacus.wd_cinema.dto.auth.RegisterRequest;
import lacus.wd_cinema.service.AuthService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户认证接口控制类
 * @author lacus
 * @version 0.5
 * @since 0.5
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/login")
    public void login(
            @RequestBody LoginRequest loginRequest,
            HttpServletRequest servletRequest) {
        authService.login(loginRequest, servletRequest);
    }

    @PostMapping("/logout")
    public void logout(HttpServletRequest servletRequest) {
        authService.logout(servletRequest);
    }

    @PostMapping("/register")
    public void register(
            @RequestBody RegisterRequest registerRequest) {
        authService.register(registerRequest);
    }
}
